//symbol ES6新增加的数据类型

let a = new String;
let b = new Number;
let c = new Boolean;
let d = new Array;
let e = new Object;

let f = Symbol();
console.log(typeof(a));
console.log(typeof(b));
console.log(typeof(f));

//Symbol是红色的, tostring是l黑色的
let jspang = Symbol('技术胖');
console.log(jspang);
console.log(jspang.toString());

//对象 中key的构建
let jspang1 = Symbol();
let obj = {
    [jspang1] : '技术胖'
}

//Symbol的打印,不能直接属性,使用数组模式
console.log(obj.jspang1);
console.log(obj[jspang1]);

//get and set 也是使用[].数组模式,这是对对象的保护
obj[jspang1] = '老民';
console.log('赋值之后:');
console.log(obj[jspang1]);

//Symobl对数组的保护,如果不想其他的数组暴露,则可以使用Symbol
let obj2 = {name:'jspang',skill:'web',age:18};

for(let item in obj2)
{
    console.log(obj2[item]);
}

console.log('保护之后,保护字段 age');
let obj3 = {name:'jspang',skill:'web'};
let age=Symbol();
obj3[age] = 18;

console.log(obj3);
for(let item in obj3)
{    
    //这里不会输出Symbol字段
    console.log(obj3[item]);
}

//直接输出
console.log(obj3[age]);